package club.ximeng.sliceupload.upload.dto;

import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author liu xm
 * @date 2022-03-08 12:01
 */
@Data
public class FileMergeParamDTO implements Serializable {

    /**
     * 文件名称
     */
    @NotBlank(message = "文件名称不能为空")
    private String fileName;
    /**
     * 文件hash,例：fcb82c7992a27ba8500630b4930f0036
     */
    @Length(min = 32, max = 32, message = "文件hash不正确")
    @NotBlank(message = "文件hash不能为空")
    private String fileHash;
    /**
     * 文件后缀
     */
    @NotBlank(message = "文件后缀不能为空")
    private String fileSuffix;
    /**
     * 分片总数
     */
    @NotNull(message = "分片总数不能为空")
    private Integer chunkTotal;


    public String fullFileName() {
        String dot = ".";
        if (!fileSuffix.contains(dot)) {
            fileSuffix = dot + fileSuffix;
        }
        return fileHash + fileSuffix;
    }
}
